package di

import DatabaseRedis
import RedisImpl
import dto.AppConfig
import io.github.crackthecodeabhi.kreds.connection.Endpoint
import io.github.crackthecodeabhi.kreds.connection.KredsClient
import io.github.crackthecodeabhi.kreds.connection.newClient
import org.koin.core.qualifier.named
import org.koin.dsl.module

val redisModule = module {
    single<KredsClient> {
        val appConfig: AppConfig = get()
        newClient(
            Endpoint(
                host = appConfig.redisHost,
                port = appConfig.redisPort.toInt()
            )
        )
    }

    single<DatabaseRedis> {
        RedisImpl(
            redis = get(),
            logger = get(
                named("Db")
            ),
            appConfig = get()
        )
    }
}
